package com.hub.utils;

import lombok.Getter;
import lombok.Setter;

/**
 *@author hub
 */
@Getter
@Setter
public class PagingResultObject<T> extends ApiResultObject<T>{
    /**
     * 每页数据数量
     */
    private long pageSize;

    /**
     * 总数据数量
     */
    private long total;

    /**
     * 当前页数
     */
    private long pageIndex;

    /**
     * 总页数
     */
    private long pageTotal;
    private PagingResultObject(int code,String message, T items,long pageIndex,long pageSize, long total){
        super(code,message,items);
        this.pageIndex = pageIndex;
        this.total = total;
        this.pageSize = pageSize;
        this.pageTotal = (total + pageSize -1)/pageSize;
    }

    /**
     * 执行失败
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> PagingResultObject failed(int code, String message){
        return new PagingResultObject<T>(code,message,null,0,0,0);
    }

    /**
     * 执行失败
     * @param message
     * @param <T>
     * @return
     */
    public static <T> PagingResultObject failed( String message){
        return new PagingResultObject<T>(ApiCodeEnum.FAILED.getCode(),message,null,0,0,0);
    }

    /**
     * 执行成功
     * @param items
     * @param pageIndex
     * @param pageSize
     * @param total
     * @param <T>
     * @return
     */
    public static <T> PagingResultObject success(T items,long pageIndex,long pageSize, long total){
        return new PagingResultObject<T>(ApiCodeEnum.SUCCESS.getCode(),"",items,pageIndex,pageSize,total);
    }

    /**
     * 执行成功
     * @param message
     * @param items
     * @param pageIndex
     * @param pageSize
     * @param total
     * @param <T>
     * @return
     */
    public static <T> PagingResultObject success(String message,T items,long pageIndex,long pageSize, long total){
        return new PagingResultObject<T>(ApiCodeEnum.SUCCESS.getCode(),message,items,pageIndex,pageSize,total);
    }
}
